import Tab from "vux/src/components/tab/tab.vue";
import TabItem from "vux/src/components/tab/tab-item.vue";

import { mapGetters, mapActions } from "vuex";
import template from "./rechargeTemplate";
const { render, staticRenderFns } = template;

export default {
  render,
  staticRenderFns,
  components: {
    Tab,
    TabItem,
  },
  data() {
    return {
      onLine: true,
      offLine: false,
      onLineList: "",
      offLineList: "",

      quickBtn: [],

      pullDownRefresh: true,

      onlineHandsel: "",
      showTip: false,
    };
  },
  created() {},
  mounted() {
    this._getRechargeList(1);
  },
  methods: {
    ...mapActions(["SET_RECHARGE_DATA"]),
    headBack() {
      this.$router.push({ path: "/wallet" });
    },
    linkFun(item, line) {
      if (item.max_recharge == -1) {
        return;
      }
      var itemVal = item;
      itemVal.line = line;
      this.SET_RECHARGE_DATA({
        Obj: itemVal,
      });
      this.$router.push({
        path: "/recharge/prePaid",
      });
    },
    onLineClick() {
      this.onLine = true;
      this.offLine = false;
      this.$refs.scroll.scrollTo(0, 0);
    },
    offLineClick() {
      this.onLine = false;
      this.offLine = true;
      this.$refs.scroll.scrollTo(0, 0);
    },
    pullingDown() {
      this._getRechargeList(0);
    },
    _getRechargeList(flag) {
      if (!JSON.parse(localStorage.getItem("isUser"))) {
        this.onLineList = [];
        this.offLineList = [];
        this.$vux.toast.show({
          text: "游客暂无权限，请先注册会员",
        });
        return;
      }
      if (flag) {
        this.$vux.loading.show();
      }
      var params = {
        token: localStorage.getItem("token"),
      };
      this.$http
        .post(this.urlRequest + "?m=api&c=recharge&a=offlineIndex", params)
        .then((res) => {
          if (flag) {
            this.$vux.loading.hide();
          } else {
            this.$refs.scroll.forceUpdate(true);
          }
          if (res.status == 0) {
            this.onLineList = res.list2;
            this.offLineList = res.list;
            this.onlineHandsel = res.online_handsel;
            this.quickBtn = res.quick_btn;
            if (res.topup_warm_tip_sw) {
              this.showTip = true;
            } else {
              this.showTip = false;
            }
          }
        })
        .catch((error) => {
          this.$refs.scroll.forceUpdate(false);
          this.$vux.loading.hide();
          this.$vux.toast.show({
            text: "数据请求超时",
          });
        });
    },
  },
  watch: {},
};

// WEBPACK FOOTER //
// ./src/components/wallet/recharge/recharge.vue
